<script>
    function preview(field) {
        field = document.getElementById( 'upload' ).value;
        //alert("Before:"+field); //--> this was comment by me
        image = document.getElementById( 'previewIMG' );

        path = 'file:///'+ field;
        path = escape(path);
        path = path.replace(/%5C/g, "/");
        path = path.replace(/%3A/g, ":");

        //alert("after="+path); //--> this was comment by me
        image.src = path;
        image.style.display = 'block';
        image.style.width = "150px";
        image.style.height = "100px";
    }

    function confirmDelete(delUrl) {
        if (confirm("คุณต้องการที่จะลบใช่ไหม")) {
            document.location = delUrl;
    }
}


</script>

<div style="width: 100%;height: 150px;background-color: #eeeeee;" align="center">
    <table>
        <tr>
            <td width="50%" align="left">
                <b>Choose CT file to upload:</b>
            </td>
            <td></td>
            <td>
                Preview Image
            </td>
        </tr>
        <tr>
            <td align="right">
                <form action="<?php echo url::base()?>/upload/uploadCT" enctype="multipart/form-data" method="post">
                    <input type="hidden" name="p_id" id="p_id" value="<?php echo $p_id?>">
                    <input type="hidden" name="c_id" id="c_id" value="<?php echo $c_id?>">
                    <input type="file" name="upload" id="upload" onChange="preview(this.value);" />
                    <br><br>
                    Description: <input type="text" id="ct_description" name="ct_description" size="30">
                    <br><br>
                    <input type="submit" name="submit" value="Upload Now">
                </form>
            </td>
            <td></td>
            <td align="center"><img id="previewIMG" style="display:none;" /></td>
        </tr>
    </table>
</div>
<div style="width: 100%;height: 160px;background-color: #eeeeee;overflow:auto;" align="center">
    <table>
        <tr>
        <?php
            $index = 1;
            if($ct_images!=null){
            foreach ($ct_images as $ct) {                
                $filename = "ct/".$ct['p_id']."/".$ct['year']."/".$ct['month']."/".$ct['filename'];
                echo "<td><table style='padding:10px;background-color: #aaaaaa;border:solid black 1px' width='200'>
                    <tr><td>
                    ".html::image($filename,array('width'=>'150','height'=>'100'))."
                    </td>
                    <td>
                        ".html::anchor('../'.$filename,html::image('assets/icon/search_48.png',array('border'=>'0','alt'=>'เปิด','width'=>'32','height'=>'32')),array('target'=>'_blank'))."
                        <br>
                        <a border=0 href=\"javascript:confirmDelete('../patient/ctscan?c_id=".$c_id."&p_id=".$p_id."&ct_id=".$ct["ct_id"]."&method=del')\">".html::image('assets/icon/cross_48.png',array('border'=>'0','alt'=>'ลบ','width'=>'32','height'=>'32'))."</a></td>
                    </tr>
                    <tr><td colspan=2>".$ct["description"]."</td></tr>
                    </table></td>";                
                $index++;
            }
          }
        ?>
        </tr>
        
    </table>
</div>

